cmake_minimum_required(VERSION 2.8.11)

project(TTKCore)

add_subdirectory(TTKCore)
add_subdirectory(TTKWidget)

include_directories(${MUSIC_COMMON_DUMPER_DIR})

get_property(MUSIC_CORE_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_KITS_HEADERS")
get_property(MUSIC_CORE_LRC_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_LRC_KITS_HEADERS")
get_property(MUSIC_WIDGET_LRC_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_LRC_KITS_HEADERS")
get_property(MUSIC_CORE_NETWORK_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_NETWORK_KITS_HEADERS")
get_property(MUSIC_CORE_PLAYLIST_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_PLAYLIST_KITS_HEADERS")
get_property(MUSIC_WIDGET_REMOTE_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_REMOTE_KITS_HEADERS")
get_property(MUSIC_CORE_SEARCH_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_SEARCH_KITS_HEADERS")
get_property(MUSIC_WIDGET_SEARCH_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_SEARCH_KITS_HEADERS")
get_property(MUSIC_CORE_TOOLS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_TOOLS_KITS_HEADERS")
get_property(MUSIC_WIDGET_TOOLS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_TOOLS_KITS_HEADERS")
get_property(MUSIC_CORE_TOOLSETS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_TOOLSETS_KITS_HEADERS")
get_property(MUSIC_WIDGET_TOOLSETS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_TOOLSETS_KITS_HEADERS")
get_property(MUSIC_WIDGET_UI_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_UI_KITS_HEADERS")
get_property(MUSIC_CORE_UTILS_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_UTILS_KITS_HEADERS")
get_property(MUSIC_CORE_VIDEO_KITS_HEADERS GLOBAL PROPERTY "MUSIC_CORE_VIDEO_KITS_HEADERS")
get_property(MUSIC_WIDGET_VIDEO_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_VIDEO_KITS_HEADERS")
get_property(MUSIC_WIDGET_CORE_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_CORE_KITS_HEADERS")
get_property(MUSIC_WIDGET_KITS_HEADERS GLOBAL PROPERTY "MUSIC_WIDGET_KITS_HEADERS")

set(HEADER_FILES
  ${MUSIC_CORE_KITS_HEADERS}
  ${MUSIC_CORE_LRC_KITS_HEADERS}
  ${MUSIC_WIDGET_LRC_KITS_HEADERS}
  ${MUSIC_CORE_NETWORK_KITS_HEADERS}
  ${MUSIC_CORE_PLAYLIST_KITS_HEADERS}
  ${MUSIC_WIDGET_REMOTE_KITS_HEADERS}
  ${MUSIC_CORE_SEARCH_KITS_HEADERS}
  ${MUSIC_WIDGET_SEARCH_KITS_HEADERS}
  ${MUSIC_CORE_TOOLS_KITS_HEADERS}
  ${MUSIC_WIDGET_TOOLS_KITS_HEADERS}
  ${MUSIC_CORE_TOOLSETS_KITS_HEADERS}
  ${MUSIC_WIDGET_TOOLSETS_KITS_HEADERS}
  ${MUSIC_WIDGET_UI_KITS_HEADERS}
  ${MUSIC_CORE_UTILS_KITS_HEADERS}
  ${MUSIC_CORE_VIDEO_KITS_HEADERS}
  ${MUSIC_WIDGET_VIDEO_KITS_HEADERS}
  ${MUSIC_WIDGET_CORE_KITS_HEADERS}
  ${MUSIC_WIDGET_KITS_HEADERS}
  ${MUSIC_LIB_DIR}/musicapplication.h
  ${MUSIC_LIB_DIR}/musicleftareawidget.h
  ${MUSIC_LIB_DIR}/musictopareawidget.h
  ${MUSIC_LIB_DIR}/musicrightareawidget.h
  ${MUSIC_LIB_DIR}/musicbottomareawidget.h
  ${MUSIC_LIB_DIR}/musicapplicationmodule.h
)

get_property(MUSIC_CORE_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_KITS_SOURCES")
get_property(MUSIC_CORE_LRC_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_LRC_KITS_SOURCES")
get_property(MUSIC_WIDGET_LRC_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_LRC_KITS_SOURCES")
get_property(MUSIC_CORE_NETWORK_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_NETWORK_KITS_SOURCES")
get_property(MUSIC_CORE_PLAYLIST_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_PLAYLIST_KITS_SOURCES")
get_property(MUSIC_WIDGET_REMOTE_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_REMOTE_KITS_SOURCES")
get_property(MUSIC_CORE_SEARCH_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_SEARCH_KITS_SOURCES")
get_property(MUSIC_WIDGET_SEARCH_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_SEARCH_KITS_SOURCES")
get_property(MUSIC_CORE_TOOLS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_TOOLS_KITS_SOURCES")
get_property(MUSIC_WIDGET_TOOLS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_TOOLS_KITS_SOURCES")
get_property(MUSIC_CORE_TOOLSETS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_TOOLSETS_KITS_SOURCES")
get_property(MUSIC_WIDGET_TOOLSETS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_TOOLSETS_KITS_SOURCES")
get_property(MUSIC_CORE_UTILS_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_UTILS_KITS_SOURCES")
get_property(MUSIC_CORE_VIDEO_KITS_SOURCES GLOBAL PROPERTY "MUSIC_CORE_VIDEO_KITS_SOURCES")
get_property(MUSIC_WIDGET_VIDEO_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_VIDEO_KITS_SOURCES")
get_property(MUSIC_WIDGET_CORE_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_CORE_KITS_SOURCES")
get_property(MUSIC_WIDGET_KITS_SOURCES GLOBAL PROPERTY "MUSIC_WIDGET_KITS_SOURCES")

set(SOURCE_FILES
  ${MUSIC_CORE_KITS_SOURCES}
  ${MUSIC_CORE_LRC_KITS_SOURCES}
  ${MUSIC_WIDGET_LRC_KITS_SOURCES}
  ${MUSIC_CORE_NETWORK_KITS_SOURCES}
  ${MUSIC_CORE_PLAYLIST_KITS_SOURCES}
  ${MUSIC_WIDGET_REMOTE_KITS_SOURCES}
  ${MUSIC_CORE_SEARCH_KITS_SOURCES}
  ${MUSIC_WIDGET_SEARCH_KITS_SOURCES}
  ${MUSIC_CORE_TOOLS_KITS_SOURCES}
  ${MUSIC_WIDGET_TOOLS_KITS_SOURCES}
  ${MUSIC_CORE_TOOLSETS_KITS_SOURCES}
  ${MUSIC_WIDGET_TOOLSETS_KITS_SOURCES}
  ${MUSIC_CORE_UTILS_KITS_SOURCES}
  ${MUSIC_CORE_VIDEO_KITS_SOURCES}
  ${MUSIC_WIDGET_VIDEO_KITS_SOURCES}
  ${MUSIC_WIDGET_CORE_KITS_SOURCES}
  ${MUSIC_WIDGET_KITS_SOURCES}
  ${MUSIC_LIB_DIR}/musicapplication.cpp
  ${MUSIC_LIB_DIR}/musicleftareawidget.cpp
  ${MUSIC_LIB_DIR}/musictopareawidget.cpp
  ${MUSIC_LIB_DIR}/musicrightareawidget.cpp
  ${MUSIC_LIB_DIR}/musicbottomareawidget.cpp
  ${MUSIC_LIB_DIR}/musicapplicationmodule.cpp
)

get_property(UI_FILES GLOBAL PROPERTY "MUSIC_UIS")

if(WIN32)
  list(APPEND SOURCE_FILES ${PROJECT_NAME}.rc)
endif()

if(TTK_QT_VERSION VERSION_GREATER "4")
  qt5_wrap_ui(UIC_FILES ${UI_FILES})
  qt5_wrap_cpp(MOC_FILES ${HEADER_FILES})

  if(TTK_BUILD_SHARED)
    add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${UIC_FILES} ${MOC_FILES} ${HEADER_FILES})
  else()
    add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES} ${UIC_FILES} ${MOC_FILES} ${HEADER_FILES})
  endif()

  list(APPEND QT5_LIBS Qt5::Core Qt5::Network Qt5::Xml Qt5::Gui Qt5::Widgets Qt5::Multimedia ${TTK_QMMP_LIBRARY} TTKLibrary TTKUi TTKExtras TTKWatcher TTKDumper zlib TTKZip)
  if(WIN32)
    list(APPEND QT5_LIBS Qt5::WinExtras Iphlpapi Version ole32 uuid)
  else(UNIX)
    list(APPEND QT5_LIBS Qt5::DBus)
  endif()
  
  if(${OPENSSL_DIR})
    if(WIN32)
      list(APPEND QT5_LIBS ${OPENSSL_DIR}/lib/libssl.a)
    else(UNIX)
      list(APPEND QT5_LIBS ${OPENSSL_DIR}/lib/libssl.so)
    endif()
  endif()

  target_link_libraries(${PROJECT_NAME} ${QT5_LIBS})
else()
  qt4_wrap_ui(UIC_FILES ${UI_FILES})
  qt4_wrap_cpp(MOC_FILES ${HEADER_FILES})

  if(TTK_BUILD_SHARED)
    add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${UIC_FILES} ${MOC_FILES} ${HEADER_FILES})
  else()
    add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES} ${UIC_FILES} ${MOC_FILES} ${HEADER_FILES})
  endif()

  list(APPEND QT4_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTMULTIMEDIA_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${TTK_QMMP_LIBRARY} TTKLibrary TTKUi TTKExtras TTKWatcher TTKDumper zlib TTKZip)
  if(WIN32)
    list(APPEND QT4_LIBS Iphlpapi Version ole32 uuid)
  else(UNIX)
    list(APPEND QT4_LIBS ${QT_QTDBUS_LIBRARY} -lQtMultimediaKit)
  endif()
  
  if(${OPENSSL_DIR})
    if(WIN32)
      list(APPEND QT5_LIBS ${OPENSSL_DIR}/lib/libssl.a)
    else(UNIX)
      list(APPEND QT5_LIBS ${OPENSSL_DIR}/lib/libssl.so)
    endif()
  endif()

  target_link_libraries(${PROJECT_NAME} ${QT4_LIBS})
endif()
